package com.elite.groovy.callback

import com.elite.groovy.util.EliteBean
import org.apache.commons.logging.Log
import org.apache.commons.logging.LogFactory

import javax.servlet.http.HttpServletRequest
import javax.servlet.http.HttpServletResponse

public class mayiAPITest implements ServiceBackInvoke{
	private static final Log log=LogFactory.getLog(mayiAPITest.class);
	public String doCallBack(EliteBean eliteBean,HttpServletRequest request,HttpServletResponse response) {

		response.setCharacterEncoding("UTF-8");
		log.debug("start mayiAPITest-----------------");
		log.debug("request--:"+request);

		String getMethod = request.getMethod();
		String callJson="";
		BufferedReader iny = null;

		def reJson = "";

		log.debug("getMethod:"+getMethod);
		if (getMethod.equals("GET")) {
			callJson = request.getParameter("data");
			log.debug("原始Get请求参数:"+callJson);
		} else {
			InputStreamReader reader = new InputStreamReader(request.getInputStream(), "UTF-8");
			iny = new BufferedReader(reader);
			String line;
			while ((line = iny.readLine()) != null) {
				callJson += line;
			}
			log.debug("原始Post请求参数:"+callJson);
		}


		try {
			

			//成功返回
			reJson= "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"+
"<PACKET TYPE=\"RESPONSE\" VERSION=\"1.0\">"+
"<HEAD>"+
"		<REQUEST_TYPE>SJBQ</REQUEST_TYPE>"+
"		<RESPONSE_CODE>1</RESPONSE_CODE>"+
"		<ERROR_MESSAGE></ERROR_MESSAGE>"+
"	</HEAD>"+
"	<BODY>"+
"<QUOTE_NO>T201507160028</QUOTE_NO>"+
"<CUSTOMERNAME>客户姓名</CUSTOMERNAME>"+
"<IDTYPE>1</IDTYPE>"+
"<CUSTOMERID>证件号码</CUSTOMERID>"+
"<FRAME_CODE>LVB10236154125874</FRAME_CODE>"+
"<MODELCODE>车辆类型</MODELCODE> "+
"<IN_STARTDATE>2018-12-12 23:23:23</IN_STARTDATE> "+
"<ENGINE_CODE>154651</ENGINE_CODE> "+
"<BRAND_NAME>奇瑞SQR7080S117轿车</BRAND_NAME>"+
"<APPLICANT_NAME>投保人姓名</APPLICANT_NAME> "+
"<INSURED_NAME>被保人姓名</INSURED_NAME>"+
"<SALES_PERSON_ORGID>0320</SALES_PERSON_ORGID>"+
"<SALES_PERSON_ORGNAME>深圳电销一部</SALES_PERSON_ORGNAME>"+
"<RISKCODE>1359</RISKCODE>"+
"<STARTDATE>2018-12-23 23:23:23</STARTDATE>"+
"<ENDDATE>2018-12-23 23:23:23</ENDDATE>"+
"	</BODY>"+
"</PACKET>";
			log.debug("mayiAPITest返回Json:"+reJson);
			return reJson;
		}
		catch(Exception e) {
			log.debug("接口处理异常"+e.getMessage());
			//失败返回
			reJson= "{\"code\":\"0\",\"description\":\"错误:"+e.getMessage()+"\"}";
			log.debug("mayiAPITest返回Json:"+reJson);
			return reJson;
		}
	}
}
